// 🎯 S1 策略模块：热冷行为评分模型
// 输入：temp（窗口内历史开奖数据）
// 输出：预测号码数组（32 个）

const allNumbers = Array.from({ length: 49 }, (_, i) =>
  (i + 1).toString().padStart(2, "0")
);

function select32NumbersByS1(temp) {
  // 初始化每个号码的统计
  const stats = {};
  allNumbers.forEach((num) => {
    stats[num] = {
      appearCount: 0,
      lastAppearDistance: Infinity,
    };
  });

  // 统计每个号码在 temp 中的出现次数和上次出现距离
  temp.forEach((entry, i) => {
    const number = entry.number;
    if (stats[number]) {
      stats[number].appearCount++;
      stats[number].lastAppearDistance = temp.length - i;
    }
  });

  // 综合评分（热度 + 冷却）
  const scoreMap = {};
  for (const num of allNumbers) {
    const { appearCount, lastAppearDistance } = stats[num];
    const score = appearCount * 2 + Math.min(lastAppearDistance, 10);
    scoreMap[num] = score;
  }

  // 得分降序，取前 32 个号码
  const finalSelected = Object.entries(scoreMap)
    .sort((a, b) => b[1] - a[1])
    .map(([num]) => num)
    .slice(0, 32);

  return finalSelected;
}

module.exports = select32NumbersByS1;
